package com.base.common.activity

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.base.common.R
import com.base.common.constant.RoutePath
import com.base.common.databinding.ActivitySimpleBinding
import dagger.hilt.android.AndroidEntryPoint

/**
 * 标准的Fragment容器Activity
 * 使用ARouter对组件化中Fragment的支持
 */

@AndroidEntryPoint
@Route(path = RoutePath.SIMPLE_PAGE_ACTIVITY)
class SimplePageActivity : AppCompatActivity(), View.OnClickListener {


   var binding: ActivitySimpleBinding?=null

    @JvmField
    @Autowired
    var path: String? = null
    @JvmField
    @Autowired
    var title: String? = null






    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
       // binding=ActivitySimpleBinding
        ARouter.getInstance().inject(this)
        binding = ActivitySimpleBinding.inflate(layoutInflater)
        setContentView(binding!!.getRoot())

        path?.let {
            val fragment= ARouter.getInstance().build(path).navigation().javaClass;

            val isFragmnet=Fragment::class.java.isAssignableFrom(fragment)

            when(isFragmnet){

                true ->   {
                    val mfragment :Class<out Fragment> = fragment as Class<out Fragment>
                    supportFragmentManager.commit {
                        add(R.id.layout_content, mfragment,null,null)
                        setReorderingAllowed(true)
                    }
                }

                else  -> Log.e(this@SimplePageActivity.localClassName,"no fragment")
            }
        }

    }

    override fun onClick(v: View?) {
        TODO("Not yet implemented")
    }
}